package com.Arsanesia.TempleRush.Controllers.Listeners;

import com.Arsanesia.TempleRush.Controllers.World;
import com.Arsanesia.TempleRush.Enumeration.Notif;
import com.Arsanesia.TempleRush.Enumeration.TempleRushSound;
import com.Arsanesia.TempleRush.Models.GameConfiguration;
import com.Arsanesia.TempleRush.Models.Geenie;
import com.Arsanesia.TempleRush.Models.Temple;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class GeenieClickListener extends ClickListener{
	private Geenie targetActor;
	private Temple templeinstance;
	private World worldinstance;
	
	public GeenieClickListener(){
		super();
	}
	public GeenieClickListener(Geenie target, World world){
		this();
		this.targetActor = target;
		this.templeinstance = world.getTemple();
		this.worldinstance = world;
	}
	@Override
	public void clicked(InputEvent event, float x, float y){
		super.clicked(event, x, y);
		
		if(worldinstance.isWorldReady() && targetActor!=null && !targetActor.isDestroyed()){
			//update the count geenie by type
			worldinstance.incrementGeenieCountByType(targetActor.getGeenieType());
			//vibrate if touch
			GameConfiguration.Vibrate();
			//play soundeffect
			GameConfiguration.playSoundEffect(TempleRushSound.convertGeenie(targetActor.getGeenieType()));
			//set geenie to destroyed
			targetActor.setDestroyed(true);
			targetActor.setStateTime(0f);
			if(templeinstance != null)
			{
				Notif notif = templeinstance.checkTouch(targetActor.getX(), targetActor.getY(),targetActor.getGeenieType());

				templeinstance.setNotif(notif);
				worldinstance.checkTouch();
			}
			
		}
	}

}
